<template>
  <div class="mod-config">
    <el-card style="height: 60%;width: 100%">
      ♊&nbsp;&nbsp;<span class="work__00001">个人优势</span>
      <div align="right">
        <a style="margin-right: 50px;float: right;">
            <img style="width: 20px; height: 20px" @click="status=true" class="icon_e__36ON5" alt="" src="">
          </a>
      </div><br>
      <div style="color: #8c939d" v-if="!status">
       {{dataForm.content}}
      </div>
      <div v-if="this.status">
          <div style="width: 80%;height: 80%">
            <el-input
              type="textarea"
              :rows="2"
              v-model="dataForm.content">
            </el-input>
          </div>
          <div align="right">
            <div style="width: 100%;" align="left">
              <el-button @click="status=false">取消</el-button>
              <el-button @click="addOrUpdateHandle">保存</el-button>
            </div>
          </div>
        </div>
    </el-card>
  </div>
</template>

<script>
  import AddOrUpdate from './advantage-add-or-update'
  import ElSlPanel from 'element-ui/packages/color-picker/src/components/sv-panel'
  export default {
    inject:['reload'],
    data () {
      return {
        status: false,
        dataForm: {
          id: 0,
          content: '',
          resumeId: ''
        },
        addOrUpdateVisible: false,
        user:{},
        resume:{},
        writeStatus:null
      }
    },
    components: {
      ElSlPanel,
      AddOrUpdate
    },
    activated () {
      this.init()
    },
    methods: {
      //根据uid查询出来的简历对象取出简历主键id
    
      // 获取数据列表
    init () {
       // this.user = JSON.parse(localStorage.getItem("user"))
       this.resume = JSON.parse(localStorage.getItem("resume"))
        this.$http({
          url: this.$http.adornUrl(`/resume/advantage/info/${this.resume.id}`),
          method: 'get'
        }).then(({data}) => {
          //if (data && data.code === 0) {
            if(data.advantage!==null){
              this.dataForm = data.advantage
                this.$emit('resumTest')
            }
         //}
        })
      
      },
      // 新增 / 修改
      addOrUpdateHandle () {
       this.writeStatus= localStorage.getItem("writeStatus");
       if(this.writeStatus==1){

    
        //this.dataForm.resumeId = this.user.userId;
        this.dataForm.resumeId = this.resume.id;
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$http({
          url: this.$http.adornUrl(`/resume/advantage/${!this.dataForm.id ? 'save' : 'update'}`),
          method: 'post',
          data: this.$http.adornData({
            'id': this.dataForm.id || undefined,
            'content': this.dataForm.content,
            'resumeId': this.dataForm.resumeId
          })
        }).then(({data}) => {
          if (data.msg==='success'){
            this.$message({
              message: '个人优势保存成功！',
              type: 'success'
            });
            //局部刷新
            this.reload();
          }else{
            this.$message.error('个人优势保存失败！');
          }
          //this.reload();
        })
          this.status = false
        
        })
      }else{
        alert("请填写基本资料")
      }
      }
    }
  }
</script>
